
<style> 
.colourRed{color: red;} 
</style> 
<link rel="stylesheet" href="static/css/loading.css" />
<script src="static/js/zxjs/loading.js"></script>
<script type="text/javascript">
var dialog_a; 
var flag_one = "add";
var defaultImg = global_param.context_name+"/systemfiles/turningimags/defaultTurningImg.png";
var upload = 'http://'+window.location.hostname+':'+window.location.port;
$(function(){
	initUserInfo();
});

function initUserInfo(){
	$.ajax({
		type: "GET",
		url: globalUtil.getTimestampUrl("/getLoginUserInfo.do"),
		data: {},
		async: false,
		dataType: 'json',
		success: function(json) {
			var user = json.user;
			if(user){
				$('#sing_personnel1').val(user.realname);
				$('#sing_personnel_id').val(user.userId);
				
			}
		}
	});
}

function musicSave(){	
	if(check()){
		$("body").startLoading();
		var form = document.getElementById('uploadMusic'), 
		formData = new FormData(form); 
		$.ajax({ 
			url:global_param.context_name+"/song/musicSave", 
			type:"post", 
			data:formData, 
			processData:false, 
			contentType:false, 
			success:function(res){ 
				$("body").stopLoading();
				if(res == 'success'){
					clean();
					//$("#main-content").load("/static/html/musicManage/personalUpload.html"+global_param.version);
					globalUtil.showSuccessMessage('操作成功');
				}else{
					globalUtil.showErrorMessage('操作失败');
				}
			}
		});
	}
}

function check(){
	var check_flag = true;
	if($('#music_name1').val()==''){
		globalUtil.showSuccessMessage("请填写歌曲名称");
		check_flag = false;
		return false;
	}
	if($('#sing_personnel1').val()==''){
		globalUtil.showSuccessMessage("请选择演唱人");
		check_flag = false;
		return false;
	}
	if($('#music_pathName_copy').val()==''){
		globalUtil.showSuccessMessage("请选择歌曲文件");
		check_flag = false;
		return false;
	}
	if($('#sys_img_path').val()==''){
		globalUtil.showSuccessMessage("歌曲背景不能为空");
		check_flag = false;
		return false;
	}
	
	if($('#music_name1').val().length > 20){
		globalUtil.showSuccessMessage("歌曲名称不能超过20字");
		check_flag = false;
		return false;
	}
	
	var t = $('#music_pathName_copy').val().substring($('#music_pathName_copy').val().length-3);
	if(t.toUpperCase() != 'MP3' && t.toUpperCase() != 'WAV'){
		globalUtil.showSuccessMessage("歌曲文件请选择mp3或wav文件");
		check_flag = false;
		return false;
	}
	
	if($('#lyric_pathName_copy').val()!=''){
		var a = $('#lyric_pathName_copy').val().substring($('#lyric_pathName_copy').val().length-3);
		if(a.toUpperCase() != 'LRC' ){
			globalUtil.showSuccessMessage("歌词文件请选择lrc文件");
			check_flag = false;
			return false;
		}
	}
			
	return check_flag;
}

function clearMusicPath(){
	$('#music_pathName').val('');
	$('#music_pathName_copy').val('');
}

function clearLyricPath(){
	$('#lyric_pathName_copy').val('');
	$('#lyric_pathName').val('');
}

function keyFile(){	
	var file = $("#music_pathName").val();
	var fileName = getFileName(file);  
	$('#music_pathName_copy').val(fileName);
}

function lyricPathFile(){	
	var file = $("#lyric_pathName").val();
	var fileName = getFileName(file);  
	$('#lyric_pathName_copy').val(fileName);
}

function getFileName(o){
    var pos=o.lastIndexOf("\\");
    return o.substring(pos+1);  
}


//歌曲背景
function MusicPic(){
	BootstrapDialog.show({												
		message: $('<div id="MusicPic" style="min-height: 450px;" ></div>').load('static/html/musicManage/MusicPic.html'),
		title: '上传歌曲背景照片',
		titleClass: 'text-center',
		closable: false,
		size:BootstrapDialog.SIZE_MIDDLE,
		buttons: [
			{
		        label: '保存',
		        cssClass:'btn btn-primary col-sm-1 col-sm-offset-4 col-xs-4 col-xs-offset-3',
		        action: function(dialog) {
		        	dialog_a = dialog;
		        	addImgs();
	        		//dialog.close();
		        }
		    },
			{
		    label: '取消',
		    cssClass:'btn btn-default col-sm-1 col-sm-offset-4 col-xs-4 col-xs-offset-3',
		    action: function(dialog) {
		    	$("#MusicPic").html("");
		        dialog.close();
		    }
		}]
	});	
}


//删除图片
function deleteImg1(){
	//删除当前页面图片
	if($('#pic_path').attr('src')==defaultImg){
		return;
	}
	if(flag_one=="edit"){
		//修改时删除
		$('#pic_path').attr('src',global_param.context_name + defaultImg);
	    $('#sys_img_path').val('');
	    toastr.success("操作成功");
	}else if(flag_one=="add"){
		//新增时删除
		  $.ajax({
		        type: "POST",
		        url: global_param.context_name + "/personnelManage/deleteImg.do",
		        data:{
		            "oldFileName": $('#sys_img_path').val(),
		            "defaultImg":defaultImg
		        },
		        async: false,
		        success: function(json) {
		        	if(json=="success"){
		        		toastr.success("操作成功");
		        		$('#pic_path').attr('src','static/img/defaultImg/defaultSquareImg.png')
		        	    $('#sys_img_path').val('');
		        	}
		        	
		        }
		    }); 
		}
}

function clean(){
	$('#music_name1').val('');
	$('#music_pathName_copy').val('');
	$('#music_pathName').val('');
	$('#lyric_pathName_copy').val('');
	$('#lyric_pathName').val('');
	$('#music_url').val('');
	$('#mv_url').val('');
	$('#pic_path').attr('src','static/img/defaultImg/defaultSquareImg.png')
	$('#sys_img_path').val('');
	$('#music_code2').val('');
	$('#flag_one').val('');
}

function checkFileExt(filename,type){
	//取出上传文件的扩展名
	var index = filename.lastIndexOf(".");
	var ext = filename.substr(index+1);
	if(type == '1'){
		var file = $("#music_pathName").val();
		var fileName = getFileName(file);  
		$('#music_pathName_copy').val(fileName);
	}else if(type == '2'){
		var file = $("#lyric_pathName").val();
		var fileName = getFileName(file);  
		$('#lyric_pathName_copy').val(fileName);
	}
}
</script>
<section class="content-header">
	<h1 class="page-name">上传歌曲</h1>
	<ol class="breadcrumb">
	</ol>
</section>
<section class="content item">
	 <div class="container-fluid">
	<div class="row">
		<div class="box">
			<div class="box-body">
				<form id="uploadMusic" enctype="multipart/form-data" method="post"> 
					<div class="col-lg-5 col-md-6 col-sm-6 col-xs-12" style="padding-top:25px;">
		              	<div class="form-group">
			              	<label for="music_name">歌曲名称<span class="colourRed">*</span></label>
			                <input type="text" class="form-control inblock form-width"  id="music_name1" name="music_name" placeholder="请输入少于20个汉字">
		              	</div>
			         </div>
					
			         <div class="col-lg-8 col-md-6 col-sm-6 col-xs-12" style="padding-top:10px;">
		              	<div class="form-group">
			              	<label for="sing_personnel">演唱人<span class="colourRed">*</span>&nbsp;&nbsp;&nbsp;</label>
			                <input type="text" readonly="readonly" id="sing_personnel1" class="form-control inblock form-width" name="sing_personnel">
		              	</div>
			         </div>
			         
			         <div class="col-lg-12 col-md-6 col-sm-6 col-xs-12" style="padding-top:10px;">
		              	<div class="form-group">
		              		<label for="music_path">歌曲文件<span class="colourRed">*</span></label>
		              		<input id="music_pathName_copy" type="text" class="form-control inblock form-width " readonly="readonly"/>
			              	<input id="music_pathName" type="file" onchange="checkFileExt(this.value,1)" accept=".mp3,.wav" class="form-control inblock form-width-copy " name="file" style="border: none"/>
			              	<div class="inblock">		              	
			              	   <a onclick="clearMusicPath()" style="cursor: pointer;">删除文件</a>
			              	</div>
		              	</div>
			         </div> 
			  
			         <div class="col-lg-12 col-md-6 col-sm-6 col-xs-12" style="padding-top:10px;">
		              	<div class="form-group">
		              		<label for="lyric_path">歌词文件<span>&nbsp;</span></label>
		              		<input id="lyric_pathName_copy" type="text" class="form-control inblock form-width " readonly="readonly" name = "lyric_pathName_copy"/>
		              	   	<input id="lyric_pathName" type="file" onchange="checkFileExt(this.value,2)" accept=".LRC" class="form-control inblock form-width-copy " name="file" style="border: none"/>
		              	    <div class="inblock">
			              	   <a onclick="clearLyricPath()" style="cursor: pointer;">删除文件</a>
			                </div>
		              	</div>
			         </div> 
			    
			         <div class="col-lg-12 col-md-6 col-sm-6 col-xs-12" style="padding-top:10px;">
		              	<div class="form-group">
			              	<label for="music_url">歌曲地址</label>
			                <input type="text" class="form-control inblock music-width" id="music_url" style="margin-left:2px" name="music_url">
		              	</div>
			         </div>
			         
			         <div class="col-lg-10 col-md-6 col-sm-6 col-xs-12" style="padding-top:10px;">
		              	<div class="form-group">
			              	<label for="mv_url">MV地址</label>
			                <input type="text" class="form-control inblock music-width" id="mv_url" style="margin-left:10px" name="mv_url">
		              	</div>
			         </div>
			
			         <div class="col-lg-12 col-md-6 col-sm-6 col-xs-12" style="padding-top:15px;">
		              	<div class="form-group " id="myPic">
			              	<label for="pic_path" style="display:table-cell; vertical-align: middle;">歌曲背景<span class="colourRed">*</span></label>
			              	<!-- <div style="border-radius:100%"></div> -->
			              	<img alt="背景" style="height:260px;margin-left:65px;margin-top:-16px" id="pic_path" src="static/img/defaultImg/defaultSquareImg.png">
			              	<div class="inblock" style="margin-top:200px;display:table-cell; vertical-align: middle;">
			                 <input type="button" onclick="MusicPic()" value="上传" class="btn btn-primary"></input> 
			                 <input type="button" onclick="deleteImg1()" value="删除" class="btn btn-default"></input>
			                </div>
		              	</div>
			         </div>
			         <input type="hidden" id="music_source" name="music_source" value="1">
			         <input type="hidden" id="sys_img_path" name="sys_img_path">
			         <input type="hidden" id="music_code2" name="music_code2">
			         <input type="hidden" id="flag_one" name="music_id">
			         <input type="hidden" id="sing_personnel_id" name="sing_personnel_id">
			    </form> 
			</div>
			<div style="padding-top:5px;">
				<input style="margin-left: 550px;width: 150px;" type="button" onclick="musicSave()" value="提交" class="btn btn-primary"></input>
			</div>
		</div>
	</div>
	    </div>
	    </section>
